﻿$(document).ready(function () {
    $('#tbl_order_list').tablePagination();
    $(".datepicker").datepicker({
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm-dd"
    });

});

function editOrder(obj) {
    var currTr = $(obj).closest("tr");

    var data = new QueryData("UserManagementProcess.ashx", "editOrder");
    data.SetQueryData(currTr, "order_info");
    var json = $.toJSON(data.Data);
    $.ajax({
        type: "POST",
        url: data.URL,
        dataType: "json",
        data: $.toJSON(data.Data),
        success: function (result) {

            if (result == "True") {
                var balanceChange = $("[name='ipt_balance_change']", currTr);
                var balanceCtl = $("[name='lbl_balance']", currTr);
                if (!isNaN(parseFloat(balanceChange.val()))) {
                    var balance = parseFloat(balanceCtl.text()) + parseFloat(balanceChange.val());
                    balanceCtl.text(balance.toFixed(2));

                }
                balanceChange.val("");
                var ddlRight = $("[name='ddl_right']", currTr);
                $("[name='lbl_right']", currTr).text($("option[value='" + ddlRight.val() + "']", ddlRight).text());
                cancelEditUser(obj);
            }
        },
        error: function (result) {
        }
    });
}


function deleteOrder(obj) {
    var currTr = $(obj).closest("tr");

    var data = new QueryData("UserManagementProcess.ashx", "deleteOrder");
    data.SetQueryData(currTr, "order_info");
    var json = $.toJSON(data.Data);
    $.ajax({
        type: "POST",
        url: data.URL,
        dataType: "json",
        data: $.toJSON(data.Data),
        success: function (result) {

            if (result == "True") {
                var balanceChange = $("[name='ipt_balance_change']", currTr);
                var balanceCtl = $("[name='lbl_balance']", currTr);
                if (!isNaN(parseFloat(balanceChange.val()))) {
                    var balance = parseFloat(balanceCtl.text()) + parseFloat(balanceChange.val());
                    balanceCtl.text(balance.toFixed(2));

                }
                balanceChange.val("");
                var ddlRight = $("[name='ddl_right']", currTr);
                $("[name='lbl_right']", currTr).text($("option[value='" + ddlRight.val() + "']", ddlRight).text());
                cancelEditUser(obj);
            }
        },
        error: function (result) {
        }
    });
}